<#include '/pages/taglib/core.ftl'>
<#include '/pages/taglib/common.ftl'>
<#include '/pages/taglib/container.ftl'>

<#assign tabId=fn.id>
<@script src="/static/espirit/scripts/espirit/eap/sa/template.js"/>
<@script src="/static/espirit/scripts/espirit/eap/sa/user.js"/>
<script>
	when('eap_sa_user', function() {
		eap_sa_user.init('${tabId}');
	});
	
	function applyUserTemplate(isTemplate) {
		eap_sa_template.applyTemplate(isTemplate, '${tabId}', '<@i18n name="privilege.applyTemlateSuccess"/>');
	}
</script>

<#if ! includePage?exists>
	<#assign includePage = "/espirit/eap/sa/user._update">
</#if>
<#assign hasPage = fn.hasPage(includePage)>
<@cs.include page=includePage + '.ftl' genDir=true>
	<@cs.extends target="name='_gen_apply">
		<#assign departments = fn.service('generic').searchAll(fn.newModel('com.espirit.eap.manager.Department')).data>
		<@treebox name="deptIds" collection=departments label="部门"/>
		
		<div class="j-form-item stdEle">
			<label class="label">${action.getText('model.espirit.eap.sa.user.template')}:</label>
			<span class="span" style="width: 500px">
				<#assign initData = fn.service('generic').searchAll(fn.newModel('com.espirit.eap.sa.Template')).data>
				<#assign initData = fn.insert(initData, 0, fn.newModel('com.espirit.eap.sa.Template'))>
				<@select collection=initData width=158 name='userTemplate.id'/>
				<input type="button" class="button" style="float: none;margin:-2px 10px 0 10px" value="${action.getText('action.apply')}" onclick="applyUserTemplate(false)">
				<#if model?if_exists.id?? && model.loginUser.userTemplatePrivileges?size gt 0>
					<a href="javascript:void(0)" onclick="openMainTab('${fn.link('/espirit/eap/sa/privilege.showFieldPrivilege')}?userId=${model.loginUser.id}','','model.espirit.eap.sa.user.fieldPermission')">
						<@i18n name='model.espirit.eap.sa.user.fieldPermission'/>
					</a>
					&nbsp;&nbsp;<a href="javascript:void(0)" onclick="openMainTab('${fn.link('/espirit/eap/sa/privilege.showFieldPrivilege')}?userId=${model.loginUser.id}&modelPrivilege=true','','model.espirit.eap.sa.user.fieldPermission')">
						<@i18n name='model.espirit.eap.sa.user.modelFieldPermission'/>
					</a>
				</#if>
			</span>
		</div>
	</@cs.extends>
	
	<@cs.extends target="_gen_tab_+"></@cs.extends><#-- remove the old permission tab-->
	
	<@cs.extends target="_gen__utilCtn_+">
		<@hidden name='model.id'/>
		<@hidden name='model.loginUser.id'/>
		
		<div id="privilegeCtn" class="loading" style="min-height: 20px;min-width: 350px;float:left;padding-left:4px;"></div>
			
		<@container name="_btnArea_" clazz="jcontainer jcontainer-buttonInput" columnCount=100>
			<@button label='action.save' onclick="eap_sa_user.saveUserPrivilege(this)"/>
			<span style="width: 5px;float: left;">&nbsp;</span>
			<@button label='action.cancel' onclick="closeInputPage(this)"/>
		</@container>
	</@cs.extends>
</@cs.include>

<#assign tmp = ps.addHiddenElement(['privileges','model.loginUser.id'])>